// JavaScript Document
var queryID = "";
var NavTopClickValue=[],NavLeftClickValue=[];
var WINDOW_SIZE = {//window尺寸
		WIDTH:1920,
		HEIGHT:1080
	},
	PAGE_SIZE={//主页面框架尺寸
		TOP_HEIGHT:90,
		LEFT_WIDTH:250,
		LEFT_MIN_WIDTH:90,
		LEFT_MIN:false//默认左导航是否最小化
	},
	PAGE_FRAME={//主页面部分框架id,需加上前缀#
		TOP:"#FrameTop",
		LEFT:"#FrameLeft",
		NAVLEFT:"#NavLeft",
		NAVLEFTONOFF:"#NavLeftOnOff",
		CONTENT:"#FrameContent",
		CONTENTIFRAME:"#iframeContent"
	};
function SET_PAGE_SIZE(){//获取window尺寸
	WINDOW_SIZE.WIDTH = window.innerWidth;
	WINDOW_SIZE.HEIGHT = window.innerHeight;
	}
function rePageSize(){//设置主页面框架尺寸
	SET_PAGE_SIZE();
	var left_width = PAGE_SIZE.LEFT_MIN ? PAGE_SIZE.LEFT_MIN_WIDTH : PAGE_SIZE.LEFT_WIDTH,
	    content_width = WINDOW_SIZE.WIDTH - left_width,
		content_height = WINDOW_SIZE.HEIGHT - PAGE_SIZE.TOP_HEIGHT;
	var left_size={width:left_width + "px",height:WINDOW_SIZE.HEIGHT + "px"},
		left_nav_size = {width:left_width + "px",height:(WINDOW_SIZE.HEIGHT - 180) + "px"},
	    top_size={width:content_width + "px",height:PAGE_SIZE.TOP_HEIGHT + "px"},
	    content_size={width:content_width + "px",height:content_height + "px"};
	$(PAGE_FRAME.TOP).css(top_size);
	$(PAGE_FRAME.LEFT).css(left_size);
	$(PAGE_FRAME.NAVLEFT).css(left_nav_size);
	$(PAGE_FRAME.CONTENT).css(content_size);
	if(PAGE_SIZE.LEFT_MIN){
		$(PAGE_FRAME.LEFT).attr({oc:"c"});
		$(PAGE_FRAME.NAVLEFTONOFF).attr({title:"展开"});
		$(PAGE_FRAME.NAVLEFT + " li").each(function(){
			$(this).attr("title",$(this).find("font").eq(0).text());
			});
	}else{
		$(PAGE_FRAME.LEFT).attr({oc:"o"});
		$(PAGE_FRAME.NAVLEFTONOFF).attr({title:""});
		$(PAGE_FRAME.NAVLEFT + " li").each(function(){
			$(this).removeAttr("title");
			});
	}
}
function clickNavLeft(cIndex){
	$(PAGE_FRAME.CONTENTIFRAME).attr('src',NavLeftClickValue[cIndex].url);
}
function setNavLeftValue(flg,dataJson){
	if(!flg){console.log('二级菜单数据，异步获取失败！');return 0;}
	if(dataJson.status == 200){
		//返回数据处理
		var ValueJson = dataJson.body;
		var strHtml="",dfIndex = -1;
		ValueJson.list.forEach(function(val,index){
			strHtml += '<li><a c-index="' + index + '" ' + ( val.df ? 'class="ac"' : '' ) + '><i xn-ico="' + val.ico + '"></i><font>' + val.title + '</font></a></li>';
			NavLeftClickValue[index]={"url":val.url};
			dfIndex = ( val.df ? index : dfIndex )
		});
		$(PAGE_FRAME.NAVLEFT).html(strHtml);
		$(PAGE_FRAME.NAVLEFT + " a").click(function(){
			$(PAGE_FRAME.NAVLEFT + " a").removeClass('ac');
			$(this).addClass('ac');
			clickNavLeft($(this).attr('c-index'));
		});
		if (NavLeftClickValue.length < 1){return 0;}
		if(dfIndex < 0){dfIndex = 0;}
		clickNavLeft(dfIndex);
	}else{
		//数据非成功状态返回信息
		console.log(dataJson);
	}
}
function setNavLeft(arrIndex){
	console.log(arrIndex);
	var pid=NavTopClickValue[arrIndex].id;
	var appDataObj=appData();
	var postJson=JSON.stringify(appDataObj);
	var getJsonUrl = API_URL_FRONT + API_URL.MENU_TWO + "pid=" + pid;
	getJsonAjax(getJsonUrl, postJson, true,setNavLeftValue);
}
function setNavTopValue(flg,dataJson){
	if(!flg){console.log('一级菜单数据，异步获取失败！');return 0;}
	if(dataJson.status == 200){
		//返回数据处理
		var ValueJson = dataJson.body;
		//FrameTop
		var strHtml="",dfIndex = -1;
		ValueJson.list.forEach(function(val,index){
			strHtml += '<a c-id="' + index + '" ' + (val.df ? 'class="ac"':'') + '>' + val.title + '</a>';
			dfIndex = (val.df ? index:dfIndex)
			NavTopClickValue[index]={"id":val.id,"df":val.df};
		});
		$(PAGE_FRAME.TOP + " .nav-top").html(strHtml);
		if (NavTopClickValue.length<1) {return 0;}
		$(PAGE_FRAME.TOP + " .nav-top a").click(function(){
			setNavLeft($(this).attr('c-id'));
			$(this).addClass("ac").siblings().removeClass("ac");
		});
		if(dfIndex < 0 ){dfIndex = 0;}
		setNavLeft(dfIndex);
	}else{
		//数据非成功状态返回信息
		console.log(dataJson);
	}
}
function setNavTop(){//一级导航数据
	var appDataObj=appData();
	var postJson=JSON.stringify(appDataObj);
	var getJsonUrl = API_URL_FRONT + API_URL.MENU_ONE;
	getJsonAjax(getJsonUrl, postJson, true,setNavTopValue);

}
function initPage(){//初始化页面
	setNavTop();
	
}
$().ready(function(){
	rePageSize();
	$(window).resize(rePageSize);
	$(PAGE_FRAME.NAVLEFTONOFF).click(function(){//展开收起左侧导航
		PAGE_SIZE.LEFT_MIN = (!PAGE_SIZE.LEFT_MIN);
		rePageSize();
	});
	initPage();
});